---
title: "Reference: Mastra.getAgent() | Core"
description: "Documentation for the `Agent.getAgent()` method in Mastra, which retrieves an agent by name."
---

# Mastra.getAgent()

The `.getAgent()` method is used to retrieve an agent. The method accepts a single `string` parameter for the agent's name.

## Usage example

```typescript copy
mastra.getAgent("testAgent");
```

## Parameters

<PropertiesTable
  content={[
    {
      name: "name",
      type: "TAgentName extends keyof TAgents",
      description:
        "The name of the agent to retrieve. Must be a valid agent name that exists in the Mastra configuration.",
    },
  ]}
/>

## Returns

<PropertiesTable
  content={[
    {
      name: "agent",
      type: "TAgents[TAgentName]",
      description:
        "The agent instance with the specified name. Throws an error if the agent is not found.",
    },
  ]}
/>

## Related

- [Agents overview](/docs/v1/agents/overview)
